package com.mayikt.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mayikt.edu.domain.EduUser;
import com.mayikt.edu.mapper.EduUserMapper;
import com.mayikt.edu.service.EduUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (EduUser)表服务实现类
 *
 * @author wangjin
 * @since 2023-10-30 09:22:59
 */
@Service("eduUserService")
public class EduUserServiceImpl extends ServiceImpl<EduUserMapper, EduUser> implements EduUserService {
    @Resource
    private EduUserMapper eduUserMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param userId 主键
     * @return 实例对象
     */
    @Override
    public EduUser queryById(Integer userId) {
        return this.eduUserMapper.selectById(userId);
    }

    /**
     * 分页查询
     *
     * @param eduUser 筛选条件
     * @return 查询结果
     */
    @Override
    public List<EduUser> queryByPage(EduUser eduUser) {
        return this.eduUserMapper.selectList(getQuery(eduUser));
    }

    private QueryWrapper getQuery(EduUser eduUser) {
        QueryWrapper queryWrapper = new QueryWrapper();

        return queryWrapper;
    }

    /**
     * 新增数据
     *
     * @param eduUser 实例对象
     * @return 实例对象
     */
    @Override
    public EduUser insert(EduUser eduUser) {
        this.eduUserMapper.insert(eduUser);
        return eduUser;
    }

    /**
     * 修改数据
     *
     * @param eduUser 实例对象
     * @return 实例对象
     */
    @Override
    public EduUser update(EduUser eduUser) {
        this.eduUserMapper.updateById(eduUser);
        return this.queryById(eduUser.getUserId());
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.eduUserMapper.deleteById(id) > 0;
    }

    @Override
    public EduUser findByUserNameEduUser(String userName) {
        LambdaQueryWrapper<EduUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EduUser::getUserName, userName);

        return eduUserMapper.selectOne(lambdaQueryWrapper);
    }
}
